import { getFilms, getFilmDetail } from '@/api/films'
import { FilmLogin, FilmCheck } from '@/api/login'
export const getFilmsAction = () => dispatch => {
    getFilms().then(res => {
        dispatch({
            type: 'setFilms',
            data: res.data.films
        })
    })
}
export const changFlag1 = () => ({
    type: 'changFlag1',
    data: {
        flag: false,
        left: 45
    }
})
export const changFlag2 = () => ({
    type: 'changFlag2',
    data: {
        flag: true,
        left: 205
    }
})
// 登录
export const filmLogin = (data = {}) => dispatch => {
    FilmLogin(data).then(res => {
        console.log(res);
        localStorage.setItem('token', res.data.token)
        localStorage.name = res.data.username
    })
}
export const filmLoginUser = e => ({
    type: 'filmLoginUser',
    data: e.target.value
})
export const filmLoginPwd = e => ({
    type: 'filmLoginPwd',
    data: e.target.value
})
export const filmCheck = (data = {}) => dispatch => {
    FilmCheck(data = {}).then(res => {
        console.log(res);
    })
}
// 详情页
export const GetFilmDetail = page => dispatch => {
    getFilmDetail(page).then(res => {
        dispatch({
            type: 'getFilmDetail',
            data: res.data.film
        })
    })
}
// 评论
export const pingLun = e => ({
    type: 'pinglun',
    data: {
        id: localStorage.name,
        neirong: e.target.value
    }
})
export const getPing = data => dispatch => {
    dispatch({
        type: 'getPing',
        data: data
    })
}
// 添加记录
export const addjilu = item => dispatch => {
    console.log(item);
    dispatch({
        type: 'addjilu',
        data: item
    })
}